package com.cs171.market.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cs171.market.entity.CartList;
import com.cs171.market.entity.OrderList;
import com.cs171.market.mapper.CartListMapper;
import com.cs171.market.mapper.OrderListMapper;
import com.cs171.market.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.jar.JarEntry;

@RestController
public class OrderListController {
    @Autowired(required = false)
    OrderListMapper orderListMapper;
    @Autowired(required = false)
    CartListMapper cartListMapper;

    @GetMapping("/orderList/{uid}")
    Object getOrderList(@PathVariable("uid")Integer uid)
    {
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("success","true");

        JSONArray jsonArray=new JSONArray();

        List<OrderList> list=orderListMapper.getOrderByUid(uid);
        for(OrderList each:list)
        {
            JSONObject  jsonObject1=new JSONObject();

            List<CartList> test = cartListMapper.getCartListByGid(18);
            JSONArray cartListJson=new JSONArray();
            for(CartList each2:test)
            {
                cartListJson.add(each2.getMessage());
            }
            jsonObject1.put("orderItems",cartListJson);

            jsonObject1.put("id",each.getOid());
            jsonObject1.put("orderStates",each.getOsend());
            jsonObject1.put("payments",each.getOprice());
            jsonArray.add(jsonObject1);
        }
        jsonObject.put("data",jsonArray);
        return jsonObject;
    }

}
